package gtkwire;

public class GTKWireMessage
{
	//--- Message types
	public static final int M_NO_MESSAGE = -1;
	public static final int M_BOOLEAN = 0;
	public static final int M_STRING = 1;
	public static final int M_INT = 2;
	public static final int M_DOUBLE = 3;
	public static final int M_FLOAT = 4;
	public static final int M_DOUBLE_ARR = 5;
	public static final int M_INT_ARR = 6;
	public static final int M_NULL = 7;

	//--- Data members
	private String widgetType;
	private String widgetName;
	private String signal;
	private int msgType;
	private Object msgObj;

	public GTKWireMessage(){}

	public GTKWireMessage( String widgetType, String widgetName, String signal, int msgType, Object msgObj )
	{
 		this.widgetType = widgetType;
 		this.widgetName = widgetName;
		this.signal = signal;
 		this.msgType = msgType;
 		this.msgObj = msgObj;
	}
	
	//--- Interface
	public String getWidgetType(){ return widgetType; }
	public String getWidgetName(){ return widgetName; }
	public String getSignal(){ return signal; }
	public String getCommand(){ return signal; }
	public int getMessageType(){ return msgType; }
	public Object getMessageObject(){ return msgObj; }
	
	//--- Message info print
	public String toString()
	{
		return	widgetName +  ", " +
			widgetType +  ", " +
			signal + ", " +
			getMessageObjectClass() +  ", " +
			getMessageObjectString();
	}
	public String getMessageObjectString()
	{
		switch( msgType )
		{
			case M_NO_MESSAGE:
				return "no message object";
			case M_DOUBLE:
				Double d = (Double) msgObj;
				return d.toString();
			case M_INT:
				Integer i = (Integer) msgObj;
				return i.toString();
			case M_INT_ARR:
				int[] iarr = (int[]) msgObj;
				return "int[], length:" + ( new Integer( iarr.length )).toString();
			case M_STRING:
				return (String) msgObj;
			case M_BOOLEAN:
				Boolean b = (Boolean) msgObj;
				return b.toString();
			default:
				return "unrecognized message type";
		}
	}
	public String getMessageObjectClass()
	{
		if( msgObj == null ) return "null";
		
		return msgObj.getClass().getName();
	}
	
}//end class
